﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.Business.Interface;
using Model.Entities;

namespace Model.Business
{
    public class UsuarioBusiness: IBaseBusiness<Usuario>, IDisposable
    {   
        private Model.Entities.PublisinosEntities context;

        public UsuarioBusiness ()
	    {
            context = Model.Entities.SystemContext.CurrentContext   ;
	    }

        public bool Login(string userName, string pass)
        {
            var user = context.Usuario.Where(u => u.Username.Equals(userName) && u.Senha.Equals(pass)).FirstOrDefault();

            if (user != null)
            {
                Framework.Security.User.UserID = user.UsuarioID;
                Framework.Security.User.UserName = user.Username;
                Framework.Security.User.Name = user.Name;
                return true;
            }
            else
                return false;

            
        }

        public bool Add(Usuario data)
        {
            context.Usuario.AddObject(data);
            int rowsAffected = context.SaveChanges();            
            return (rowsAffected > 0);
        }

        public bool Update(Usuario data)
        {
            throw new NotImplementedException();
        }

        public bool Delete(Usuario data)
        {
            throw new NotImplementedException();
        }

        public Usuario Select(int id)
        {
            throw new NotImplementedException();
        }

        public List<Usuario> Select()
        {
            throw new NotImplementedException();
        }

        void IDisposable.Dispose()
        {
            context = null;
            GC.Collect();
        }
    }
}
